package de.gameduell.framework.application.level {
	import de.gameduell.framework.application.controller.SingleplayerController;

	/**
	 * @author daal
	 */
	public class LevelController extends SingleplayerController {

		protected var _levels:Vector.<Level>;
		protected var _currentLevel:Level;
		protected var _levelsCount : uint;
		protected var _currentLevelIndex : uint;

		public function LevelController() {
			_levelsCount = 0;
			_currentLevelIndex = 0;
			_levels = new Vector.<Level>();
		}

		public function get levels():Vector.<Level> {
			return _levels;
		}

		public function get currentLevel():Level {
			return _currentLevel;
		}
		
		public function get currentLevelIndex():uint {
			return _currentLevelIndex;
		}
		
		public function get levelsCount():uint {
			return _levelsCount;
		}
		
		public function set levelsCount(levelsCount:uint):void {
			_levelsCount = levelsCount;
		}

		//means that levelsCount should be surely set.
		public function isLastLevel() : Boolean {
			return _levelsCount == _currentLevelIndex;
		}

		public function initLevel(level : Level):void {
			_currentLevelIndex++;
			_levels.push(level);
			_currentLevel = level;

			_currentLevel.addEventListener(LevelEvent.LEVEL_START, levelStartHandler);
			_currentLevel.addEventListener(LevelEvent.LEVEL_COMPLETE, levelCompleteHandler);			_currentLevel.addEventListener(LevelEvent.LEVEL_FAIL, levelFailHandler);

			var levelEvent : LevelEvent = new LevelEvent(LevelEvent.LEVEL_CREATED);
			levelEvent.level = _currentLevel;
			dispatchEvent(levelEvent);
		}

		protected function levelStartHandler(event:LevelEvent):void {
		}

		protected function levelCompleteHandler(event:LevelEvent):void {
		}

		protected function levelFailHandler(event:LevelEvent):void {
		}
	}
}
